#include "hitbox.h"
#include "point.h"
#include <cmath>
#include <typeinfo>

hitbox::hitbox(const point* ancrage) : position(ancrage)
{}

hitboxRECT::hitboxRECT(point* ancrage,int taillex,int tailley,int taillez) : hitbox(ancrage), taillex(taillex), tailley(tailley), taillez(taillez)
{}

bool hitboxRECT::colpoint(double x,double y,double z)
{
	return ((x<position->Getx()+taillex/2 && x>position->Getx()-taillex/2)
		&&(z<position->Getz()+taillez/2 && z>position->Getz()-taillez/2)
		&&(y<position->Gety()+tailley/2 && y>position->Gety()-tailley/2));
}

bool const hitboxRECT::collision(const hitboxRECT & OR)
{
	return (
		(this->colpoint(OR.position->Getx()-OR.taillex/2,OR.position->Gety()-OR.tailley/2,OR.position->Getz()-OR.taillez/2))||
		(this->colpoint(OR.position->Getx()+OR.taillex/2,OR.position->Gety()-OR.tailley/2,OR.position->Getz()-OR.taillez/2))||
		(this->colpoint(OR.position->Getx()-OR.taillex/2,OR.position->Gety()-OR.tailley/2,OR.position->Getz()+OR.taillez/2))||
		(this->colpoint(OR.position->Getx()+OR.taillex/2,OR.position->Gety()-OR.tailley/2,OR.position->Getz()+OR.taillez/2))||
		(this->colpoint(OR.position->Getx()-OR.taillex/2,OR.position->Gety()+OR.tailley/2,OR.position->Getz()-OR.taillez/2))||
		(this->colpoint(OR.position->Getx()+OR.taillex/2,OR.position->Gety()+OR.tailley/2,OR.position->Getz()-OR.taillez/2))||
		(this->colpoint(OR.position->Getx()-OR.taillex/2,OR.position->Gety()+OR.tailley/2,OR.position->Getz()+OR.taillez/2))||
		(this->colpoint(OR.position->Getx()+OR.taillex/2,OR.position->Gety()+OR.tailley/2,OR.position->Getz()+OR.taillez/2))||
		//centre
		(this->colpoint(OR.position->Getx(),OR.position->Gety(),OR.position->Getz()))
		);
}

double module(double x0,double y0,double z0,double x1,double y1,double z1)
{
	return sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0) + (z1-z0)*(z1-z0));
}

hitboxCERCL::hitboxCERCL(point* ancrage,double rayon): hitbox(ancrage), rayon(rayon)
{}

bool hitboxCERCL::colpoint(double x,double y,double z)
{
	if (module(position->Getx(),position->Gety(),position->Getz(),x,y,z)<rayon)
		return true;
	else
		return false;
}

bool const hitboxCERCL::collision(const hitboxCERCL & OC)
{
	return (module(position->Getx(),position->Gety(),position->Getz(),OC.position->Getx(),OC.position->Gety(),OC.position->Getz())<rayon+OC.rayon);
}
